/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dib;

import java.awt.*;
import javax.swing.JOptionPane;

/**
 *
 * @author alex
 */
public class Arista extends Canvas{

    int posxi,posyi,posxf,posyf;
    Integer valorDelCamino=null;
    Nodo origen;
    boolean cu;

    public Integer getValorCamino() {
        return valorDelCamino;
    }

    public void setValorDelCamino(Integer valorDelCamino) {
        this.valorDelCamino = valorDelCamino;
    }

    public int getPosxf() {
        return posxf;
    }

    public void setPosxf(int posxf) {
        this.posxf = posxf;
    }

    public int getPosyf() {
        return posyf;
    }

    public void setPosyf(int posyf) {
        this.posyf = posyf;
    }

    public Nodo getOrigen() {
        return origen;
    }

    public void setOrigen(Nodo origen) {
        this.origen = origen;
    }
    
    public Arista(int posxi, int posyi, int posxf, int posyf) {
        this.posxi = posxi;
        this.posyi = posyi;
        this.posxf = posxf;
        this.posyf = posyf;
    }

    public Arista(int posxi, int posyi, int posxf, int posyf, Integer valorDelCamino) {
        this.posxi = posxi;
        this.posyi = posyi;
        this.posxf = posxf;
        this.posyf = posyf;
        this.valorDelCamino = valorDelCamino;
    }

    public Arista(int posxi, int posyi, int posxf, int posyf, Nodo origen, boolean cu) {
        this.posxi = posxi;
        this.posyi = posyi;
        this.posxf = posxf;
        this.posyf = posyf;
        this.origen = origen;
        this.cu = cu;
       
    }
    public void getValorDelCamino() throws Throwable
    {
        boolean t;
        do {
            t=false;
                String dato= JOptionPane.showInputDialog(null, "Ingrese el valor del camino");
                if(dato==null){
                    this.finalize();
                    t=false;
                    return;
                }
        try {
            if(dato.equals("")){
                JOptionPane.showMessageDialog(null, "Debe de ingresar el valor de camino");
                t=true;
            }
            else
            {
                if(!t)
                    this.valorDelCamino= Integer.parseInt(dato);
            }
        } catch (Exception e) {
            t=true;
            JOptionPane.showMessageDialog(null, "El valor del camino debe ser numeros enteros");
        }
        } while (t);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2= (Graphics2D)g;
        g2.setColor(Color.black);
        BasicStroke b = new BasicStroke(3);
        g2.setStroke(b);
        g2.drawLine(posxi, posyi, posxf, posyf);
        int resultadoI=(posyi-posyf)/(posxi-posxf);
     
        g2.drawLine(posxf, posyf, posxf-5,(posyf+5));
        g2.drawLine(posxf, posyf, posxf-5,(posyf-5));
        if(this.valorDelCamino!=null)
            g2.drawString(this.valorDelCamino.toString(), ((posxi+posxf)/2),(((posyf+posyi)/2)-20));
    }
    
    
}
